package com.example.controller;


import com.example.entity.Category;
import com.example.entity.Link;
import com.example.service.LinkService;
import com.example.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Date;
import java.util.List;

@RequestMapping("/content/link")
@RestController
public class LinkController {

    @Autowired
    private LinkService linkService;


    @GetMapping("/list")
    public ResponseResult getList(@PathParam("pageNum") int pageNum, @PathParam("pageSize") int pageSize,@PathParam("name") String name,@PathParam("status") String status){
        return linkService.getList(pageNum,pageSize,name,status);
    }

    @GetMapping("/{id}")
    public ResponseResult getLink(@PathVariable Long id){
        return ResponseResult.okResult(linkService.getById(id));
    }

    @DeleteMapping("/{ids}")
    public ResponseResult deleteLinks(@PathVariable List<Long> ids){
        return ResponseResult.okResult(linkService.removeByIds(ids));
    }

    @PutMapping()
    public ResponseResult updateCategory(@RequestBody Link link){
        link.setUpdateTime(new Date());
        return ResponseResult.okResult(linkService.updateById(link));
    }

    @PostMapping()
    public ResponseResult saveCategory(@RequestBody Link link){
        return linkService.saveLink(link);
    }
}
